/****************************************************
	文件：HtmlParse.cs
	作者：HuskyT
	邮箱：1005240602@qq.com
	日期：2020/7/23 11:32:50
	功能：Html 解析
*****************************************************/

using System;
using System.Linq;
using System.Collections.Generic;
using System.Text.RegularExpressions;

namespace HTSpider
{
    public static class HtmlParse
    {
        public static string Match(string data, string pattern)
        {
            Regex reg = new Regex(pattern);
            Match matches = reg.Match(data);
            return matches.Groups[1].Value;
        }
        public static List<string> Matches(string data, string pattern)
        {
            List<string> ret = new List<string>();
            MatchCollection matchCollection = Regex.Matches(data, pattern);
            for (int i = 0; i < matchCollection.Count; i++)
            {
                ret.Add(matchCollection[i].Value);
            }
            return ret;
        }
        public static List<string> Split(string data, char seperateChar)
        {
            return data.Split(seperateChar).ToList();
        }
        public static string Replace(string data, string oldStr,string newStr)
        {
            return data.Replace(oldStr, newStr);
        }
        public static string Replace(string data ,string[] oldStrArray,string newStr)
        {
            string ret = "";
            foreach (var old in oldStrArray)
            {
                ret = data.Replace(old, newStr);
            }
            return ret;
        }
        /// <summary>  
        /// 验证只包含汉字  
        /// </summary>  
        public static bool IsChinese(string data)
        {
            string pattern = @"^[\u4e00-\u9fa5]+$";
            return Regex.IsMatch(data, pattern);
        }
        /// <summary>
        /// 验证只包含数字
        /// </summary>
        public static bool IsNumber(string data)
        {
            string pattern = @"^\d+$";
            return Regex.IsMatch(data, pattern);
        }
    }
}
